﻿using System;
using System.Collections.Generic;
using System.Data;
using BCL.Entity;
using NazSoft.Framework;
using System.Linq;
using NazSoft.Framework.Extensions;

namespace BCL.Repository
{
    public class FeedBackRepository
    {
        public int Save(Feedback feedback)
        {
            object[] objName = { "Name", "Subject", "Email", "Descriptions", "CreatedDate" };
            object[] objValue = { feedback.Name, feedback.Subject, feedback.Email, feedback.Descriptions, feedback.CreatedDate };

            var parameter = new System.Data.SqlClient.SqlParameter("@Id", 0);

            parameter.Direction = ParameterDirection.Output;

            SqlHelper helpclass = new SqlHelper();
            var result = helpclass.ExecuteNonQuery("SP_FeedBackSave", objName, objValue, (cmd) =>
            {
                cmd.Parameters.Add(parameter);
            });
            int Id = Convert.ToString(parameter.Value).ToInt32Safe();


            return Id;
        }

        public List<Feedback> GetFeedBack(DateTime toDate, DateTime fromDate)
        {
            object[] objName = { "Todate", "FromDate" };
            object[] objValue = { toDate, fromDate };

            SqlHelper helpclass = new SqlHelper();
            DataTable dataTable = helpclass.GetDataTable("Get_FeedBackTwoDates", objName, objValue);

            List<Feedback> model = CollectionHelper.ConvertTo<Feedback>(dataTable).ToList();

            return model;
        }
    }
}
